package com.example.demo.utils;

/**
 * @author FENGYU
 * @description
 * @date 2023/8/15 15:50
 */
public class ValidationUtil {
    private static boolean isEmptyArray(Object array)
    {
        int length = 0;
        if(array instanceof int[])
        {
            length = ((int[])array).length;
        }
        else if(array instanceof byte[])
        {
            length = ((byte[])array).length;
        }
        else if(array instanceof short[])
        {
            length = ((short[])array).length;
        }
        else if(array instanceof char[])
        {
            length = ((char[])array).length;
        }
        else if(array instanceof float[])
        {
            length = ((float[])array).length;
        }
        else if(array instanceof double[])
        {
            length = ((double[])array).length;
        }
        else if(array instanceof long[])
        {
            length = ((long[])array).length;
        }
        else if(array instanceof boolean[])
        {
            length = ((boolean[])array).length;
        }
        else
        {
            length = ((Object[])array).length;
        }
        if(length==0)
        {
            return true;
        }
        return false;
    }

    public static boolean isNotEmpty(Object aObj) {
        return !isEmpty(aObj);
    }
    public static boolean isEmpty(Object aObj)
    {
        if (aObj instanceof String)
        {
            return isEmpty((String)aObj);
        }
        else if (aObj instanceof StringBuilder)
        {
            return isEmpty((StringBuilder)aObj);
        }
        else if (aObj instanceof StringBuffer)
        {
            return isEmpty(aObj.toString());
        }
        else if (aObj instanceof Long)
        {
            return isEmpty((Long)aObj);
        }
        else if (aObj instanceof java.util.Date)
        {
            return isEmpty((java.util.Date)aObj);
        }
        else if (aObj instanceof java.util.Collection)
        {
            return isEmpty((java.util.Collection)aObj);
        }
        else if (aObj instanceof java.util.Map)
        {
            return isEmpty((java.util.Map)aObj);
        }
        else if(aObj!=null && aObj.getClass().isArray())
        {
            return isEmptyArray(aObj);
        }
        else
        {
            return isNull(aObj);
        }
    }
    public static boolean isNull(Object oStr)
    {
        if (oStr == null)
        {
            return true;
        }
        else
        {
            return false;
        }
    }
}
